package com.employee.crud.Dao;

import com.employee.crud.Employee;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Repository

public class EmployeeDao implements dao {

    public EmployeeDao() {}

    private static Map<Int, Employee> employees = new HashMap<>();

    static {
        Employee e0 = new Employee();
        Employee e1 = new Employee();
        Employee e2 = new Employee();
        Employee e3 = new Employee();
        Employee e4 = new Employee();
        employees.put(e0.getId(),e0);
        employees.put(e1.getId(),e1);
        employees.put(e2.getId(),e2);
        employees.put(e3.getId(),e3);
        employees.put(e4.getId(),e4);
    }

    @Override
    public Employee getEmployeeByName(Int id) {
        return employees.get(id);
    }

    @Override
    public List<Employee> getEmployeeList() {
        List<Employee> employeeList = new ArrayList<>(employees.values());
        return employeeList;
    }

    @Override
    public String addEmployee(Employee employee) {
        employees.put(employee.getId(),employee);
        return "success";
    }

    @Override
    public String updateEmployee(Int id, Employee employee) {
        employees.get(id).setName(employee.getName());
        employees.get(id).setAge(employee.getAge());
        employees.get(id).setGander(employee.getGender());
        return "success";
    }

    @Override
    public String deleteEmployee(Int id) {
        employees.remove(id);
        return "success";
    }
}
